package com.jinpeng.counter.util;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author 86184
 */
@Component
public class DbUtil {
    private static DbUtil dbUtil = null;

    private DbUtil(){ };

    @Resource
    private SqlSessionTemplate sqlSessionTemplate;

    private void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate){
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    public SqlSessionTemplate getSqlSessionTemplate() {
        return this.sqlSessionTemplate;
    }

    @PostConstruct
    private void init(){
        dbUtil = new DbUtil();
        dbUtil.setSqlSessionTemplate(this.sqlSessionTemplate);
    }


    public static long getId(){
        Long res = dbUtil.getSqlSessionTemplate().selectOne("testMapper.queryBalance");
        if (res == null){
            return -1;
        }else {
            return  res;
        }
    }

}
